float baseline_align;
- gchar *filename; /* Only used with GTK_IMAGE_ANIMATION, GTK_IMAGE_PIXBUF */
- gchar *resource_path; /* Only used with GTK_IMAGE_PIXBUF */
+ gchar *filename; /* Only used with GTK_IMAGE_ANIMATION, GTK_IMAGE_SURFACE */
+ gchar *resource_path; /* Only used with GTK_IMAGE_SURFACE */
};
enum
{
PROP_0,
- PROP_PIXBUF,
PROP_SURFACE,
PROP_FILE,
PROP_ICON_SIZE,
GtkWidgetClass *widget_class;
gobject_class = G_OBJECT_CLASS (class);
-
+
gobject_class->set_property = gtk_image_set_property;
gobject_class->get_property = gtk_image_get_property;
gobject_class->finalize = gtk_image_finalize;
widget_class->unrealize = gtk_image_unrealize;
widget_class->style_updated = gtk_image_style_updated;
- image_props[PROP_PIXBUF] =
- g_param_spec_object ("pixbuf",
- P_("Pixbuf"),
- P_("A GdkPixbuf to display"),
- GDK_TYPE_PIXBUF,
- GTK_PARAM_READWRITE);
-
image_props[PROP_SURFACE] =
g_param_spec_boxed ("surface",
P_("Surface"),
switch (prop_id)
{
- case PROP_PIXBUF:
- gtk_image_set_from_pixbuf (image, g_value_get_object (value));
- break;
case PROP_SURFACE:
gtk_image_set_from_surface (image, g_value_get_boxed (value));
break;
switch (prop_id)
{
- case PROP_PIXBUF:
- g_value_set_object (value, _gtk_icon_helper_peek_pixbuf (&priv->icon_helper));
- break;
case PROP_SURFACE:
g_value_set_boxed (value, _gtk_icon_helper_peek_surface (&priv->icon_helper));
break;
*
* If you need to detect failures to load the file, use
* gdk_pixbuf_new_from_file() to load the file yourself, then create
- * the #GtkImage from the pixbuf. (Or for animations, use
+ * the #GtkImage from the surface. (Or for animations, use
* gdk_pixbuf_animation_new_from_file()).
*
* The storage type (gtk_image_get_storage_type()) of the returned
* The #GtkImage does not assume a reference to the
* pixbuf; you still need to unref it if you own references.
* #GtkImage will add its own reference rather than adopting yours.
- *
+ *
+ * This is a helper for gtk_image_new_from_surface, and you can't
+ * get back the exact pixbuf once this is called, only a surface.
+ *
* Note that this function just creates an #GtkImage from the pixbuf. The
* #GtkImage created will not react to state changes. Should you want that,
* you should use gtk_image_new_from_icon_name().
*/
if (gdk_pixbuf_animation_is_static_image (anim))
- gtk_image_set_from_pixbuf (image,
- gdk_pixbuf_animation_get_static_image (anim));
+ {
+ cairo_surface_t *surface = gdk_cairo_surface_create_from_pixbuf (gdk_pixbuf_animation_get_static_image (anim),
+ scale_factor, _gtk_widget_get_window (GTK_WIDGET (image)));
+ gtk_image_set_from_surface (image, surface);
+ cairo_surface_destroy (surface);
+ }
else
- gtk_image_set_from_animation (image, anim);
-
- _gtk_icon_helper_set_pixbuf_scale (&priv->icon_helper, scale_factor);
+ {
+ gtk_image_set_from_animation (image, anim);
+ _gtk_icon_helper_set_pixbuf_scale (&priv->icon_helper, scale_factor);
+ }
g_object_unref (anim);
priv->filename = g_strdup (filename);
-
+
g_object_thaw_notify (G_OBJECT (image));
}
}
if (gdk_pixbuf_animation_is_static_image (animation))
- gtk_image_set_from_pixbuf (image, gdk_pixbuf_animation_get_static_image (animation));
+ {
+ cairo_surface_t *surface = gdk_cairo_surface_create_from_pixbuf (gdk_pixbuf_animation_get_static_image (animation),
+ scale_factor, _gtk_widget_get_window (GTK_WIDGET (image)));
+ gtk_image_set_from_surface (image, surface);
+ cairo_surface_destroy (surface);
+ }
else
- gtk_image_set_from_animation (image, animation);
-
- _gtk_icon_helper_set_pixbuf_scale (&priv->icon_helper, scale_factor);
+ {
+ gtk_image_set_from_animation (image, animation);
+ _gtk_icon_helper_set_pixbuf_scale (&priv->icon_helper, scale_factor);
+ }
priv->resource_path = g_strdup (resource_path);
* @pixbuf: (allow-none): a #GdkPixbuf or %NULL
*
* See gtk_image_new_from_pixbuf() for details.
+ *
+ * Note: This is a helper for gtk_image_new_from_surface, and you can't
+ * get back the exact pixbuf once this is called, only a surface.
+ *
**/
void
gtk_image_set_from_pixbuf (GtkImage *image,
GdkPixbuf *pixbuf)
{
- GtkImagePrivate *priv = gtk_image_get_instance_private (image);
+ cairo_surface_t *surface = NULL;
g_return_if_fail (GTK_IS_IMAGE (image));
g_return_if_fail (pixbuf == NULL ||
GDK_IS_PIXBUF (pixbuf));
- g_object_freeze_notify (G_OBJECT (image));
-
- gtk_image_clear (image);
- if (pixbuf != NULL)
- _gtk_icon_helper_set_pixbuf (&priv->icon_helper, pixbuf);
+ if (pixbuf)
+ surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, 1, gtk_widget_get_window (GTK_WIDGET (image)));
- g_object_notify_by_pspec (G_OBJECT (image), image_props[PROP_PIXBUF]);
+ gtk_image_set_from_surface (image, surface);
- g_object_thaw_notify (G_OBJECT (image));
+ if (surface)
+ cairo_surface_destroy (surface);
}
/**
return _gtk_icon_helper_get_storage_type (&priv->icon_helper);
}
-/**
- * gtk_image_get_pixbuf:
- * @image: a #GtkImage
- *
- * Gets the #GdkPixbuf being displayed by the #GtkImage.
- * The storage type of the image must be %GTK_IMAGE_EMPTY or
- * %GTK_IMAGE_PIXBUF (see gtk_image_get_storage_type()).
- * The caller of this function does not own a reference to the
- * returned pixbuf.
- *
- * Returns: (nullable) (transfer none): the displayed pixbuf, or %NULL if
- * the image is empty
- **/
-GdkPixbuf*
-gtk_image_get_pixbuf (GtkImage *image)
-{
- GtkImagePrivate *priv = gtk_image_get_instance_private (image);
-
- g_return_val_if_fail (GTK_IS_IMAGE (image), NULL);
-
- return _gtk_icon_helper_peek_pixbuf (&priv->icon_helper);
-}
-
/**
* gtk_image_get_surface:
* @image: a #GtkImage
{
switch (storage_type)
{
- case GTK_IMAGE_PIXBUF:
- g_object_notify_by_pspec (G_OBJECT (image), image_props[PROP_PIXBUF]);
- break;
case GTK_IMAGE_ANIMATION:
g_object_notify_by_pspec (G_OBJECT (image), image_props[PROP_PIXBUF_ANIMATION]);
break;
case GTK_IMAGE_SURFACE:
g_object_notify_by_pspec (G_OBJECT (image), image_props[PROP_SURFACE]);
break;
+ case GTK_IMAGE_PIXBUF:
+ g_warning ("pixbuf not supported");
+ break;
case GTK_IMAGE_EMPTY:
default:
break;
gtk_image_get_gicon (image, &icon, NULL);
return gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_MENU);
}
- else if (storage_type == GTK_IMAGE_PIXBUF)
+ else if (storage_type == GTK_IMAGE_SURFACE)
{
gint width, height;
-
- if (gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &width, &height))
- {
- GdkPixbuf *src_pixbuf, *dest_pixbuf;
- GtkWidget *cloned_image;
- src_pixbuf = gtk_image_get_pixbuf (image);
- dest_pixbuf = gdk_pixbuf_scale_simple (src_pixbuf, width, height,
- GDK_INTERP_BILINEAR);
-
- cloned_image = gtk_image_new_from_pixbuf (dest_pixbuf);
- g_object_unref (dest_pixbuf);
+ if (gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &width, &height))
+ {
+ cairo_surface_t *src_surface, *dest_surface;
+ GtkWidget *cloned_image;
+ gint scale = gtk_widget_get_scale_factor (GTK_WIDGET (image));
+ cairo_t *cr;
+
+ src_surface = gtk_image_get_surface (image);
+ dest_surface =
+ gdk_window_create_similar_image_surface (gtk_widget_get_window (GTK_WIDGET(image)),
+ CAIRO_FORMAT_ARGB32,
+ width * scale, height * scale, scale);
+ cr = cairo_create (dest_surface);
+ cairo_set_source_surface (cr, src_surface, 0, 0);
+ cairo_scale (cr,
+ width / cairo_image_surface_get_width (src_surface),
+ height / cairo_image_surface_get_height (src_surface));
+ cairo_paint (cr);
+ cairo_destroy (cr);
+
+ cloned_image = gtk_image_new_from_surface (dest_surface);
+ cairo_surface_destroy (dest_surface);
return cloned_image;
}
{
GtkWidget *image = GTK_WIDGET (data);
- GdkPixbuf *pixbuf = gtk_image_get_pixbuf (GTK_IMAGE (image));
+ cairo_surface_t *surface = gtk_image_get_surface (GTK_IMAGE (image));
- gtk_selection_data_set_pixbuf (selection_data, pixbuf);
+ gtk_selection_data_set_surface (selection_data, surface);
}
static void
gpointer data)
{
GtkWidget *image = GTK_WIDGET (data);
-
- GdkPixbuf *pixbuf;
+ cairo_surface_t *surface;
if (gtk_selection_data_get_length (selection_data) < 0)
return;
- pixbuf = gtk_selection_data_get_pixbuf (selection_data);
+ surface = gtk_selection_data_get_surface (selection_data);
- gtk_image_set_from_pixbuf (GTK_IMAGE (image), pixbuf);
+ gtk_image_set_from_surface (GTK_IMAGE (image), surface);
}
static gboolean
GtkWidget *window, *grid;
GtkWidget *label, *image;
GtkIconTheme *theme;
- GdkPixbuf *pixbuf;
+ cairo_surface_t *surface;
gchar *icon_name = "help-browser";
gchar *anim_filename = NULL;
GIcon *icon;
gtk_grid_attach (GTK_GRID (grid), label, 0, 1, 1, 1);
theme = gtk_icon_theme_get_default ();
- pixbuf = gtk_icon_theme_load_icon (theme, icon_name, 48, 0, NULL);
- image = gtk_image_new_from_pixbuf (pixbuf);
+ surface = gtk_icon_theme_load_surface (theme, icon_name, 48, gtk_widget_get_scale_factor (window), gtk_widget_get_window (window), 0, NULL);
+ image = gtk_image_new_from_surface (surface);
gtk_grid_attach (GTK_GRID (grid), image, 2, 1, 1, 1);
gtk_drag_source_set (image, GDK_BUTTON1_MASK,